/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package VIEW;

import CONTROLLERS.SecHandTradeInController;
import java.awt.CardLayout;

/**
 *
 * @author weak_2030
 */
public class TradeInNew extends javax.swing.JPanel {
    SecHandTradeInController secHandTradeInController;
    CardLayout card; 
    /**
     * Creates new form TradeInNew
     */
    public TradeInNew() {
        try{
        initComponents();
        secHandTradeInController = new SecHandTradeInController(historyTable, fromDate, toDate);
        jButton1.doClick();
        tradeHistoryDialog.setLocationRelativeTo(null);
        }catch(Exception e){
            e.printStackTrace();
            
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup2 = new javax.swing.ButtonGroup();
        tradeHistoryDialog = new javax.swing.JDialog();
        jScrollPane1 = new javax.swing.JScrollPane();
        historyTable = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        fromDate = new datechooser.beans.DateChooserCombo();
        jLabel4 = new javax.swing.JLabel();
        toDate = new datechooser.beans.DateChooserCombo();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        tradeInCards = new javax.swing.JPanel();
        tradeProduct1 = new VIEW.TradeProduct();
        tradeToBrandNew1 = new VIEW.TradeToBrandNew();
        addToSecondHandList1 = new VIEW.AddToSecondHandList();
        viewSecondHandList1 = new VIEW.ViewSecondHandList();

        tradeHistoryDialog.setTitle("Trade-in History");
        tradeHistoryDialog.setBounds(new java.awt.Rectangle(0, 0, 900, 600));
        tradeHistoryDialog.setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);

        historyTable.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        historyTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Date", "Product Name", "Quantity", "Swapped To", "Type of Trade"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        historyTable.setRowHeight(20);
        jScrollPane1.setViewportView(historyTable);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Trade-In History");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel3.setText("From:");

        fromDate.setWeekStyle(datechooser.view.WeekDaysStyle.FULL);
        fromDate.addSelectionChangedListener(new datechooser.events.SelectionChangedListener() {
            public void onSelectionChange(datechooser.events.SelectionChangedEvent evt) {
                fromDateOnSelectionChange(evt);
            }
        });
        fromDate.addCommitListener(new datechooser.events.CommitListener() {
            public void onCommit(datechooser.events.CommitEvent evt) {
                fromDateOnCommit(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel4.setText("To:");

        toDate.setWeekStyle(datechooser.view.WeekDaysStyle.FULL);
        toDate.addSelectionChangedListener(new datechooser.events.SelectionChangedListener() {
            public void onSelectionChange(datechooser.events.SelectionChangedEvent evt) {
                toDateOnSelectionChange(evt);
            }
        });
        toDate.addCommitListener(new datechooser.events.CommitListener() {
            public void onCommit(datechooser.events.CommitEvent evt) {
                toDateOnCommit(evt);
            }
        });

        javax.swing.GroupLayout tradeHistoryDialogLayout = new javax.swing.GroupLayout(tradeHistoryDialog.getContentPane());
        tradeHistoryDialog.getContentPane().setLayout(tradeHistoryDialogLayout);
        tradeHistoryDialogLayout.setHorizontalGroup(
            tradeHistoryDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tradeHistoryDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tradeHistoryDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 880, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(tradeHistoryDialogLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(fromDate, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(toDate, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        tradeHistoryDialogLayout.setVerticalGroup(
            tradeHistoryDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tradeHistoryDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(tradeHistoryDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(fromDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(toDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 518, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        setBackground(new java.awt.Color(204, 204, 204));

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Trade-In");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(-10, 0, 1040, -1));

        buttonGroup2.add(jRadioButton2);
        jRadioButton2.setText("Add To Secondhand Product List");
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });
        jPanel1.add(jRadioButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 62, -1, -1));

        buttonGroup2.add(jRadioButton3);
        jRadioButton3.setText("Trade/Swap To Secondhand Products");
        jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton3ActionPerformed(evt);
            }
        });
        jPanel1.add(jRadioButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 62, -1, -1));

        buttonGroup2.add(jRadioButton4);
        jRadioButton4.setText("Trade/Swap To Brand New Products");
        jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton4ActionPerformed(evt);
            }
        });
        jPanel1.add(jRadioButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(725, 62, -1, -1));

        jButton1.setText("View Secondhand Product List");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 62, -1, -1));

        jButton2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton2.setText("View Trade-In History");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(890, 0, -1, -1));

        tradeInCards.setLayout(new java.awt.CardLayout());
        tradeInCards.add(tradeProduct1, "tradeProductCard");
        tradeInCards.add(tradeToBrandNew1, "tradeToBrandNewCard");
        tradeInCards.add(addToSecondHandList1, "addToSecondHandCard");
        tradeInCards.add(viewSecondHandList1, "viewTradeInCard");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tradeInCards, javax.swing.GroupLayout.DEFAULT_SIZE, 1181, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 1081, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tradeInCards, javax.swing.GroupLayout.DEFAULT_SIZE, 629, Short.MAX_VALUE))
        );

        card = (CardLayout)tradeInCards.getLayout();
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
        card.show(tradeInCards, "addToSecondHandCard");
         jButton1.setEnabled(true);
    }//GEN-LAST:event_jRadioButton2ActionPerformed

    private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton4ActionPerformed
        card.show(tradeInCards, "tradeToBrandNewCard");
        jButton1.setEnabled(true);
        
    }//GEN-LAST:event_jRadioButton4ActionPerformed

    private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton3ActionPerformed
        card.show(tradeInCards, "tradeProductCard");
        jButton1.setEnabled(true);
    }//GEN-LAST:event_jRadioButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
         card.show(tradeInCards, "viewTradeInCard");
        jButton1.setEnabled(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        secHandTradeInController.updateTradeInHistoryTable();
        tradeHistoryDialog.setVisible(true);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void fromDateOnSelectionChange(datechooser.events.SelectionChangedEvent evt) {//GEN-FIRST:event_fromDateOnSelectionChange
        secHandTradeInController.updateTradeInHistoryTable();
    }//GEN-LAST:event_fromDateOnSelectionChange

    private void toDateOnSelectionChange(datechooser.events.SelectionChangedEvent evt) {//GEN-FIRST:event_toDateOnSelectionChange
        secHandTradeInController.updateTradeInHistoryTable();
    }//GEN-LAST:event_toDateOnSelectionChange

    private void fromDateOnCommit(datechooser.events.CommitEvent evt) {//GEN-FIRST:event_fromDateOnCommit
        secHandTradeInController.updateTradeInHistoryTable();
    }//GEN-LAST:event_fromDateOnCommit

    private void toDateOnCommit(datechooser.events.CommitEvent evt) {//GEN-FIRST:event_toDateOnCommit
        secHandTradeInController.updateTradeInHistoryTable();
    }//GEN-LAST:event_toDateOnCommit


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private VIEW.AddToSecondHandList addToSecondHandList1;
    private javax.swing.ButtonGroup buttonGroup2;
    private datechooser.beans.DateChooserCombo fromDate;
    private javax.swing.JTable historyTable;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JScrollPane jScrollPane1;
    private datechooser.beans.DateChooserCombo toDate;
    private javax.swing.JDialog tradeHistoryDialog;
    private javax.swing.JPanel tradeInCards;
    private VIEW.TradeProduct tradeProduct1;
    private VIEW.TradeToBrandNew tradeToBrandNew1;
    private VIEW.ViewSecondHandList viewSecondHandList1;
    // End of variables declaration//GEN-END:variables
}
